package com.sicheng.lc.周赛.分类.思维;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/2 9:55
 */
public class 基于陈述统计最多好人数 {
    //https://leetcode.cn/problems/maximum-good-people-based-on-statements/
    public int maximumGood(int[][] statements) {

        int n = statements.length;
        int max = 0, j;
        for (int i = 1; i < 1 << n; i++) {
            int cnt = 0;
            for (j = 0; j < n; j++) {
                if ((i >> j & 1) == 1) {
                    cnt++;
                    if (!check(i, statements[j])) {
                        break;
                    }
                }
            }
            if (j == n)
                max = Math.max(max, cnt);
        }

        return max;

    }

    private boolean check(int i, int[] statements) {
        for (int k = 0; k < statements.length; k++) {
            if (statements[k] != 2 && (i >> k & 1) != statements[k])
                return false;
        }
        return true;
    }

    public static void main(String[] args) {
        基于陈述统计最多好人数 s = new 基于陈述统计最多好人数();
        int[][] statements = {{2, 0}, {0, 2}};
        System.out.println(s.maximumGood(statements));
    }
}
